#!/bin/bash
#
# mailquotad	This shell script takes care of starting and stopping
#		the mailquotad daemon.
#
# chkconfig: 345 80 20
# description: mailquotad daemon.
# probe: false
# processname: mailquotad
# pidfile: /var/run/quotad/mailquotad.pid

# Comments to support LSB init script conventions
### BEGIN INIT INFO
# Provides: mailquotad
# Required-Start: $network
# Requires-Stop: $network
# Default-Start:  3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop mailquotad
# Description: mailquotad - mailquotad daemon
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0

[ -f /usr/sbin/mailquotad ] || exit 0

if [ -f /etc/sysconfig/mailquotad ]; then
    . /etc/sysconfig/mailquotad
fi

RETVAL=0
start() {
	if [ -n "`/sbin/pidof mailquotad`" ]; then
	    echo -n "mailquotad: already running"
	    RETVAL=$?
	    echo
	    return $RETVAL
	fi
        echo -n "Starting mailquotad: "
        daemon mailquotad $OPTIONS
        RETVAL=$?
	echo
        [ $RETVAL = 0 ] && touch /var/lock/subsys/mailquotad
        return $RETVAL
}
stop() {
	echo -n "Stopping mailquotad: "
	killproc mailquotad
	RETVAL=$?
	echo
	[ $RETVAL = 0 ] && rm -f /var/lock/subsys/mailquotad /var/run/mailquotad.pid
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  status)
        status mailquotad
	RETVAL=$?
	;;
  restart|reload)
	stop
	start
	;;
  condrestart)
	if [ -f /var/lock/subsys/mailquotad ] ; then
	    stop
	    start
	fi
	;;
  *)
	echo "Usage: $0 {start|stop|status|restart|condrestart|reload}"
	exit 1
esac

exit $RETVAL
